package com.sunny.l49;

public class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return dfs(p, q);
    }
    public boolean dfs(TreeNode p, TreeNode q){
        if(null == p && null == q)
            return true;
        if(null == p || null == q)
            return false;
        if(p == q || p.val == q.val){
            return dfs(p.left, q.left) && dfs(p.right, q.right);
        }
        return false;
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}
